package com.hrt.datasender.web.bcplcpointconfig;

import com.hrt.datasender.datadao.model.BcParamMap212Model;
import com.hrt.db.DBManager;

import java.util.List;
import java.util.UUID;

public final class BcPlcPointConfigService {

    private static volatile BcPlcPointConfigService instance;

    private BcPlcPointConfigService() {

    }

    public static BcPlcPointConfigService getInstance() {
        if (instance == null) {
            synchronized (BcPlcPointConfigService.class) {
                if (instance == null) {
                    instance = new BcPlcPointConfigService();
                }
            }
        }
        return instance;
    }

    public void create(BcPlcPointConfigModel model) {
        model.setId(UUID.randomUUID().toString());
        DBManager.getORMExecuter().create(model);
    }

    public void update(BcPlcPointConfigModel model) {
        DBManager.getORMExecuter().update(model);
    }

    public void delete(String id) {
        BcPlcPointConfigModel model = new BcPlcPointConfigModel();
        model.setId(id);
        DBManager.getORMExecuter().delete(model);
    }


    public List<BcPlcPointConfigModel> getList() {
        String sql = "SELECT * FROM BC_PLC_POINT_CONFIG t ORDER BY t.PARAM_CODE_BUS,t.POINT_POSITION";
        List<BcPlcPointConfigModel> models = DBManager.getORMExecuter().getModelListSQL(sql,null,BcPlcPointConfigModel.class);
        return models;
    }
}
